home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / mail / check < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  1.6 KB  |  56 lines

  1. #!/bin/ksh
  2. # check: report on users' mail
  3. # @(#) check.ksh 2.0 96/11/01
  4. # 90/05/30 john h. dubois iii (john@armory.com)
  5. # 90/11/30 changed to expect mail files in user's home dir
  6. # 92/02/16 added help option
  7. # 93/11/30 Made #!/bin/ksh for server
  8. # 95/12/30 Get home dir from /etc/passwd!
  9. # 96/11/01 Use ksh to get home dir.  Tell whether user has new mail.
  10.  
  11. cd /    # for server
  12. name=check
  13. if [ "$1" = -h ]; then
  14.     echo \
  15. "$name: check for whether users have mail.
  16. Usage: $name [username ...]
  17. For each named user whose mail spool file is in a readable directory,
  18. $name will report the amount of waiting mail and the last time that mail
  19. was read or received.
  20. If no username is given, the report is done for the user invoking $name."
  21.     exit 0
  22. fi
  23. typeset -L8 puser
  24. typeset -i a m c s
  25. [ $# -eq 0 ] && set -- $USER
  26. for user in "$@"; do
  27.     homedir=$(print -r ~$user)
  28.     if [ "$homedir" = "~$user" ]; then
  29.     print -ru2 -- "$user: no such user."
  30.     exit 1
  31.     fi
  32.     if [ -x $homedir ]; then
  33.     puser=$user
  34.     mailbox="$homedir/.mailbox"
  35.     if [ -f "$mailbox" ]; then
  36.         if type stat > /dev/null; then
  37.         set -- $(stat -t"%a %b %e '%y %I:%M%p %Z" -nfamcsA '-c ' -- \
  38.         "$mailbox" 2>/dev/null)
  39.         a=$1 m=$2 c=$3 s=$4
  40.         shift 4
  41.         [ m -ge a -a m -eq c ] && amount=some || amount=none
  42.         print -r -- \
  43.     "$puser has $(((s+1023) / 1024))K of mail ($amount new), last received $*"
  44.         else
  45.         set -- $(/bin/ls -og -- "$mailbox")
  46.         print -- \
  47.         "$puser has $3 characters of mail, last received $4 $5 $6"
  48.         fi
  49.     else
  50.         print -u2 "$puser has no mail spool file."
  51.     fi
  52.     else
  53.     print -u2 "Can't access $user's home directory."
  54.     fi
  55. done
  56.